home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / qex / qexcvsd / mxtest.c < prev    next >
Text File  |  1990-07-24  |  4KB  |  213 lines

  1. /* MX-COM MX709 CODEC board test program */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <alloc.h>
  6. #include <bios.h>
  7. #include <ctype.h>
  8. #include <dos.h>
  9.  
  10. #include "mxcom.h"
  11.  
  12. char *
  13. prompt(char *pmt)
  14. {
  15.     static char reply[120];
  16.  
  17.     printf("%s", pmt);
  18.     gets(reply);
  19.     return reply;
  20. }
  21.  
  22. void
  23. usage(void)
  24. {
  25.     puts("MXTEST -- Tests KE3Z MXCOM CODEC card");
  26.     puts("Usage mxtest [-v]");
  27.     puts("      -v = use vox");
  28.     exit(0);
  29. }
  30.  
  31. int
  32. main(int argc, char *argv[])
  33. {
  34.     char *buf, *p;
  35.     int i, stat, pgm;
  36.     unsigned n;
  37.     FILE *fil;
  38.     int over;
  39.     char vox = 0;
  40.  
  41.     for (i = 1; i < argc; i++)
  42.     {
  43.         if (argv[i][0] != '-')
  44.             usage();
  45.         switch (toupper(argv[i][1]))
  46.         {
  47.         case 'V':
  48.             vox = 1;
  49.             break;
  50.         default:
  51.             usage();
  52.         }
  53.     }
  54.     while (1)
  55.     {
  56.         p = prompt("CODEC Programming bits (0-7) or P to measure power: ");
  57.         if (*p == 'P' || *p == 'p')
  58.         {
  59.             i = atoi(prompt("Page size (0-7): ")) & 7;
  60.             outportb(MX_B, i | 8);
  61.             over = 0;
  62.             while (1)
  63.             {
  64.                 if ((i = bioskey(1)) != 0)
  65.                     if ((i & 0xff) == 0x1b)
  66.                         break;
  67.                 if ((i = (inportb(MX_STAT) & 0x24)) != 0)
  68.                 {
  69.                     if (i & 0x20)
  70.                         over++;
  71.                     i = inportb(MX_PWR);
  72.                     printf("(%02X)", i);
  73.                 }
  74.             }
  75.             bioskey(0);
  76.             printf("\n%d page overspills\n", over);
  77.             continue;
  78.         }
  79.         i = atoi(p) & 7;
  80.         pgm = (i << 5) | (i << 2);
  81.         n = atoi(prompt("# samples: "));
  82.         if (n == 0)
  83.         {
  84.             p = prompt("File to load: ");
  85.             if (*p == 0)
  86.                 continue;
  87.             if ((fil = fopen(p, "rb")) == NULL)
  88.             {
  89.                 perror(p);
  90.                 continue;
  91.             }
  92.             if (fseek(fil, 0L, SEEK_END))
  93.             {
  94.                 perror(p);
  95.                 continue;
  96.             }
  97.             n = (int) ftell(fil) - sizeof pgm;
  98.             if ((buf = malloc(n)) == NULL)
  99.             {
  100.                 puts("Insufficient memory");
  101.                 fclose(fil);
  102.                 continue;
  103.             }
  104.             fseek(fil, 0L, SEEK_SET);
  105.             fread(&i, sizeof i, 1, fil);
  106.             if (i != -1)
  107.                 pgm = i;
  108.             if (fread(buf, 1, n, fil) != n)
  109.             {
  110.                 perror(p);
  111.                 fclose(fil);
  112.                 continue;
  113.             }
  114.             printf("%u bytes loaded, CODEC programming=%d\n", n, pgm >> 5);
  115.             fclose(fil);
  116.         } else if ((buf = malloc(n)) == NULL)
  117.         {
  118.             puts("Insufficient memory");
  119.             continue;
  120.         } else
  121.         {
  122.             outportb(MX_B, 0x3a);
  123.             outportb(MX_A, pgm + 2);
  124.             if (vox)
  125.             {
  126.                 while ((inportb(MX_PWR) & 0xf) < 3)
  127.                     if ((bioskey(1) & 0xff) == 0x1b)
  128.                     {
  129.                         bioskey(0);
  130.                         outportb(MX_B, 0);
  131.                         free(buf);
  132.                         continue;
  133.                     }
  134.             } else
  135.             {
  136.                 puts("Press any key to start recording...");
  137.                 if ((bioskey(0) & 0xff) == 0x1b)
  138.                 {
  139.                     outportb(MX_B, 0);
  140.                     free(buf);
  141.                     continue;
  142.                 }
  143.             }
  144.             puts("Recording.");
  145.             p = buf;
  146.             *p++ = inportb(MX_ENC);
  147.             i = n - 1;
  148.             while (i > 0)
  149.             {
  150.                 stat = inportb(MX_STAT);
  151.                 if (stat & 8)
  152.                 {
  153.                     printf("Encode overspill after %d bytes\n", n-i);
  154.                     break;
  155.                 } else if (stat & 1)
  156.                 {
  157.                     *p++ = inportb(MX_ENC);
  158.                     i--;
  159.                 }
  160.             }
  161.             if (stat & 8)
  162.             {
  163.                 free(buf);
  164.                 continue;
  165.             }
  166.             printf("%u bytes received\n", n);
  167.         }
  168.         while (1)
  169.         {
  170.             puts("Hit any key to play back, S to save, ESC to record...");
  171.             if ((i = (bioskey(0) & 0xff)) == 0x1b)
  172.                 break;
  173.             if (i == 'S' || i == 's')
  174.             {
  175.                 p = prompt("File name: ");
  176.                 if (*p == 0)
  177.                     continue;
  178.                 if ((fil = fopen(p, "wb")) == NULL)
  179.                 {
  180.                     perror(p);
  181.                     continue;
  182.                 }
  183.                 fwrite(&pgm, sizeof pgm, 1, fil);
  184.                 if (fwrite(buf, 1, n, fil) != n)
  185.                     perror(p);
  186.                 fclose(fil);
  187.                 continue;
  188.             }
  189.             outportb(MX_A, pgm + 2);
  190.             outportb(MX_B, 0x38);
  191.             p = buf;
  192.             over = 0;
  193.             outportb(MX_DEC, *p++);
  194.             i = n - 1;
  195.             while (i > 0)
  196.             {
  197.                 stat = inportb(MX_STAT);
  198.                 if (stat & 0x12)
  199.                 {
  200.                     if (stat & 0x10)
  201.                         over++;
  202.                     outportb(MX_DEC, *p++);
  203.                     i--;
  204.                 }
  205.             }
  206.             outportb(MX_B, 0);
  207.             printf("%d decode overspills\n", over);
  208.         }
  209.         free(buf);
  210.         outportb(MX_A, 0);
  211.         outportb(MX_B, 0);
  212.     }
  213. }